package com.xzzz.irda.tracker.core.adapter.dubbo;//package com.xzzz.expand.trace.dubbo;
//
//import com.xzzz.expand.trace.core.Tracer;
//import com.xzzz.expand.trace.core.common.TraceConstants;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.common.constants.CommonConstants;
//import org.apache.dubbo.common.extension.Activate;
//import org.apache.dubbo.rpc.*;
//
///**
// * dubbo trace 过滤器
// *
// * @author wangyf
// * @since 1.2.0
// */
//@Slf4j
//@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER})
//public class TraceDubboFilter implements Filter {
//
//    public TraceDubboFilter() {
//        log.info("[TRACKERS] Dubbo过滤器初始化完成");
//    }
//
//    @Override
//    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
//        try {
//            // 从 dubbo 调用方获取传递的 trace
//            String traceId = RpcContext.getContext().getAttachment(TraceConstants.TRACE_ID_KEY);
//            traceId = Tracer.begin(traceId).getTraceId();
//            RpcContext.getContext().setAttachment(TraceConstants.TRACE_ID_KEY, traceId);
//            return invoker.invoke(invocation);
//        } finally {
//            // trace 结束
//            RpcContext.getContext().removeAttachment(TraceConstants.TRACE_ID_KEY);
//            Tracer.end();
//        }
//    }
//}
